import React, { useState, useEffect } from 'react';
import { Button } from 'antd';
import styles from './index.less';
import { exportExcel } from 'xlsx-oc';

import enUs from './en-US';
import zhCn from './zh-CN';

export default class extends React.Component {
  // 导出表格
  exportDefaultExcel = () => {
    const header = [
      { k: 'key', v: 'key' },
      { k: 'zhcn', v: '中文' },
      { k: 'enus', v: '英文' },
    ];
    var list = [];
    var find = (index, parentKye, data, enUsData) => {
      // 深层
      if (typeof data == 'object') {
        for (let key in data) {
          find(index + 1, parentKye + '.' + key, data[key], enUsData[key]);
        }
      }
      //插入
      if (typeof data == 'string') {
        list.push({
          key: parentKye,
          zhcn: data,
          enus: enUsData,
        });
      }
    };
    for (let key in zhCn) {
      find(1, key, zhCn[key], enUs[key]);
    }
    console.log(list);
    const fileName = '国际化.xlsm';
    exportExcel(header, list, fileName);
  };

  render() {
    return (
      <div className={styles.page}>
        <Button
          type="primary"
          onClick={() => {
            this.exportDefaultExcel();
          }}
        >
          导出
        </Button>
      </div>
    );
  }
}
